package org.lc.scoretj.dto;

/**
 * 分页查询参数DTO
 */
public class PageQueryDTO {
    
    private int page = 1;  // 页码，从1开始
    private int size = 10;  // 每页大小
    private String sortBy;  // 排序字段
    private String sortOrder = "asc";  // 排序方向：asc/desc
    
    public PageQueryDTO() {}
    
    public PageQueryDTO(int page, int size) {
        this.page = page;
        this.size = size;
    }
    
    public int getPage() {
        return page;
    }
    
    public void setPage(int page) {
        this.page = page < 1 ? 1 : page;
    }
    
    public int getSize() {
        return size;
    }
    
    public void setSize(int size) {
        this.size = size < 1 ? 10 : size > 100 ? 100 : size;
    }
    
    public String getSortBy() {
        return sortBy;
    }
    
    public void setSortBy(String sortBy) {
        this.sortBy = sortBy;
    }
    
    public String getSortOrder() {
        return sortOrder;
    }
    
    public void setSortOrder(String sortOrder) {
        this.sortOrder = "desc".equalsIgnoreCase(sortOrder) ? "desc" : "asc";
    }
    
    /**
     * 获取偏移量
     * @return 偏移量
     */
    public int getOffset() {
        return (page - 1) * size;
    }
}